package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Taeyang
 * @date 2025-04-23
 */
@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
public class BaseCategoryApiController {

    private final BaseCategoryService baseCategoryService;

    @Autowired
    public BaseCategoryApiController(BaseCategoryService baseCategoryService) {
        this.baseCategoryService = baseCategoryService;
    }

    /**
     * 查询所有的分类信息
     *
     * @return Result
     */
    @GetMapping("/getBaseCategoryList")
    public Result<List<JSONObject>> getBaseCategoryList() {
        return Result.ok(baseCategoryService.getIndexCategory());
    }

    /**
     * 根据一级分类id查询属性信息
     *
     * @param category1Id 一级分类id
     * @return Result
     */
    @GetMapping("/findAttribute/{category1Id}")
    public Result<List<BaseAttribute>> findAttribute(@PathVariable("category1Id") Long category1Id) {
        return Result.ok(baseCategoryService.findAttribute(category1Id));
    }

    /**
     * 根据一级分类id查询三级分类列表的前7个
     *
     * @param category1Id
     * @return
     */
    @GetMapping("/findTopBaseCategory3/{category1Id}")
    public Result findTopBaseCategory3(@PathVariable("category1Id") Long category1Id) {
        return Result.ok(baseCategoryService.findTopBaseCategory3(category1Id));
    }

    /**
     * 根据一级分类id查询所有的二级分类和三级分类
     *
     * @param category1Id
     * @return
     */
    @GetMapping("/getBaseCategoryList/{category1Id}")
    public Result getBaseCategoryList(@PathVariable("category1Id") Long category1Id) {
        return Result.ok(baseCategoryService.getBaseCategoryList(category1Id));
    }
}

